package gui;

/**
 *	@(#)HighlightObserver.java
 *
 *	The <code>HighlightObserver</code> instances observe game objects
 *	that might wish to be highlighted.
 *
 *	@author Grzegorz Kobiela
 *	@version 1.0 2008/4/24
 */
public final class HighlightObserver
implements java.util.Observer
{
	/** The highlight label. */
	private javax.swing.JLabel label;

	/** The target component. */
	private javax.swing.JLayeredPane target;

	/**
	 *	Creates a new <code>HighlightObserver</code> instance
	 *	for the given target component.
	 *	@param target the target component
	 */
	public HighlightObserver(javax.swing.JLayeredPane target) {
		this.target = target;
		label = null;
	}

	/**
	 *	This method is called whenever the observed object is changed.
	 *	@param obs the observed object
	 *	@param obj the argument
	 */
	public void update(java.util.Observable obs, Object obj) {
		if(obj instanceof Boolean) {
			if((Boolean)obj) {
				if(label != null) return;
				label = GameUtilities.createHighlight(obs);
				target.add(label, main.Antiquity.getLayer("LandHighlight"));
			} else {
				if(label == null) return;
				target.remove(label);
				target.invalidate();
				target.repaint();
				label = null;
			}
		}
	}
}